#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 10010;
int tree[maxn*30][27];
int tol = 0;
char s[maxn][30];
int flag[maxn*30];
void insert(char *s)
{
	int rt = 0;
	int len = strlen(s);
	for(int i = 0;i<len;i++)
	{
		int id = s[i]-'a';
		if(!tree[rt][id]) tree[rt][id] = ++tol;
		flag[rt]++;
		rt = tree[rt][id];
	}
}
void find(char *s)
{
	int rt = 0;
	int len = strlen(s);
	for(int i = 0;i<len;i++)
	{
		if(flag[rt]==1) break;
		int id = s[i]-'a';
		printf("%c",s[i]);
		rt = tree[rt][id];	
	}	
}
int main()
{
	int cnt = 0;
	memset(flag,0,sizeof(flag));
	while(scanf("%s",s[cnt++])!=EOF)
	{
		insert(s[cnt-1]);
	}
	for(int i = 0;i<cnt;i++)
	{
		printf("%s ",s[i]);
		find(s[i]);
		printf("\n");
	}
}
